<?php
/*
作者 :张仁美
时间 :2014年7月21日
用法
<?php $this->widget('ext.ubutton',array('cname'=>"video","class"=>"ckeditor"));?>
<?php $this->widget('ext.ubutton',array('cname'=>"special","class"=>"ckeditor"));?>
<?php $this->widget('ext.ubutton',array('cname'=>"pic","class"=>"ckeditor"));?>
<?php $this->widget('ext.ubutton',array('cname'=>"link","class"=>"ckeditor"));?>
*/
class ubutton extends CWidget
{
	
	private $_assetsUrl;//资源文件路径
	public $cname; //唯一标识识别
	public $title; //标题
	public $class; //id

	public function init()
	{
		$this->title=$this->gettitle($this->cname);
		$this->registerClientScript();
	}

	private function gettitle($cname){
	
	    switch($cname){
		   
            case "video":
				return "选择视频";
			break;
			case "table":
				return "插入表格";
			break;
			case "idvideo":
				return "选择视频";
				break;
			case "idpic":
				return "选择图片";
			break;
			case "special":
				return "选择PC专题";
			break;
			case "pic":
				return "选择图库图片";
			break;
            case "hardwareidpic":
                return "选择图库图片";
                break;
			case "link":
				return "选择链接";
			break;
			case "indexpic":
				return "图库图片";
			break;
			case "htmltoubb":
				return "转UBB代码";
			break;
			case "newsid":
				return "选择评测";
			break;
			case "liver":
				return "选择主播";
			break;
			case "xgnewsid":
				return "选择相关新闻";
			break;
			case "oloday":
				return "选择新报";
			break;
            case "syzt":
				return "选择手游专题";
			break;
			case "shop":
				return "选择商品";
			break;
			case "sygame":
				return "选择游戏";
			break;
			case "bzvideo":
				return "插入视频";
				break;
			case "h3":
				return "H3标签";
				break;
            case "gamecard":
                return "游戏卡片";
                break;
            case "review":
                return "评测模板";
                break;
            case "picedit":
                return "图注/Alt";
                break;
		}

	}

	public function cycini()
	{
			$form_id = 'ubutton';
			$title=$label=$this->title;
			switch($this->cname){
			    case "video":
				   $url = Yii::app()->createUrl('ubutton/ubutton/video');
			       break;
			    case "bzvideo":
				   $url = Yii::app()->createUrl('ubutton/ubutton/bzvideo');
			       break;
			    case "special":
				   $url = Yii::app()->createUrl('ubutton/ubutton/special');
			       break;
			    case "pic":
				   $url = Yii::app()->createUrl('ubutton/ubutton/pic');
			       break;
			    case "link":
				   $url = Yii::app()->createUrl('ubutton/ubutton/link');
			       break;
				case "indexpic":
				   $url = Yii::app()->createUrl('ubutton/ubutton/indexpic');
			       break;
			    case "htmltoubb":
			       	$url = Yii::app()->createUrl('ubutton/ubutton/htmltoubb/class/'.$this->class);
					break;
			    case "idvideo":
			    	$url = Yii::app()->createUrl('ubutton/ubutton/idvideo');
					break;
                case "hardwareidpic":
                    $url = Yii::app()->createUrl('ubutton/ubutton/hardwareidpic');
                    break;
			    case "idpic":
			    	$url = Yii::app()->createUrl('ubutton/ubutton/idpic');
					break;
			    case "newsid":
			    	$url = Yii::app()->createUrl('ubutton/ubutton/newsid?class='.$this->class);
					break;
			    case "liver":
			    	$url = Yii::app()->createUrl('ubutton/ubutton/liver');
					break;
			    case "xgnewsid":
			    	$url = Yii::app()->createUrl('ubutton/ubutton/xgnewsid');
					break;
			    case "oloday":
			    	$url = Yii::app()->createUrl('ubutton/ubutton/oloday');
					break;
			    case "syzt":
			    	$url = Yii::app()->createUrl('ubutton/ubutton/syzt');
					break;
			    case "shop":
			    	$url = Yii::app()->createUrl('ubutton/ubutton/shop');
					break;
			    case "table":
			    	$url = Yii::app()->createUrl('ubutton/ubutton/table');
					break;
			    case "sygame":
			    	$url = Yii::app()->createUrl('ubutton/ubutton/sygame');
					break;
			    case "h3":
			    	$url = Yii::app()->createUrl('ubutton/ubutton/h3');
					break;
                case "gamecard":
                    $url = Yii::app()->createUrl('ubutton/ubutton/gamecard');
                    break;
                case "review":
                    $url = Yii::app()->createUrl('ubutton/ubutton/review');
                    break;
                case "picedit":
                    $url = Yii::app()->createUrl('ubutton/ubutton/picedit?class='.$this->class);
                    break;
			}
			
			$html="";
			/*
			$html.="<span  style='color:#fff;font-weight:bold;color:#666' class=\"multi_pic_btn\" onclick=\"javascript:showDialogs('".$url."','".$form_id."','".$title."','".$this->class."','".$this->cname."')\" >".$label."</span>";
			*/
			$html.="<input type=\"button\" class=\"default_btn\"  onclick=\"javascript:showDialogs('".$url."','".$form_id."','".$title."','".$this->class."','".$this->cname."','".Yii::app()->controller->module->id."')\" value='".$label."'>";
			echo $html;
	}
 
	public function run()
	{
	    $this->cycini();
        echo '<script src="'.Yii::app()->request->baseUrl.'/protected/modules/ubutton/assets/js/common.js?as3"></script>';
    }
	
	protected function registerClientScript()
	{
      	//调用attachment模块的资源文件
		$this->_assetsUrl=Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('application.modules.ubutton.assets'));
		$cs=Yii::app()->clientScript;
		$cs->registerCssFile($this->_assetsUrl.'/css/common.css');
//	    $cs->registerScriptFile($this->_assetsUrl.'/js/common.js?20211013');
		//artdialog
		$cs->registerScriptFile(Yii::app()->request->baseUrl."/public/js/art_dialog/artDialog.source.js?skin=blue");
		$cs->registerScriptFile(Yii::app()->request->baseUrl."/public/js/art_dialog/plugins/iframeTools.source.js");
		$cs->registerScriptFile(Yii::app()->request->baseUrl."/public/js/art_dialog/_doc/highlight/highlight.pack.js");
		$cs->registerScriptFile(Yii::app()->request->baseUrl."/public/js/art_dialog/_doc/highlight/languages/javascript.js");
		
		
	}
}